home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / Xsun / sunKbd.diffs < prev    next >
Encoding:
Text File  |  1991-11-18  |  29.7 KB  |  1,081 lines

  1. *** /tmp/,RCSt1921911    Sun Nov 17 16:15:34 1991
  2. --- sunKbd.c    Wed Jul 11 13:47:12 1990
  3. ***************
  4. *** 47,82 ****
  5.   #endif
  6.   
  7.   
  8.   #define NEED_EVENTS
  9.   #include "sun.h"
  10. ! #include <stdio.h>
  11. ! #include "Xproto.h"
  12.   #include "keysym.h"
  13. ! #include "inputstr.h"
  14.   
  15.   typedef struct {
  16.       int              trans;              /* Original translation form */
  17.   } SunKbPrivRec, *SunKbPrivPtr;
  18.   
  19. - extern CARD8 *sunModMap[];
  20. - extern KeySymsRec sunKeySyms[];
  21.   extern void    ProcessInputEvents();
  22.   extern void    miPointerPosition();
  23.   
  24.   static void       sunBell();
  25.   static void       sunKbdCtrl();
  26. ! static Firm_event *sunKbdGetEvents();
  27.   static void       sunKbdProcessEvent();
  28.   static void       sunKbdDoneEvents();
  29. - int            autoRepeatKeyDown = 0;
  30. - int            autoRepeatDebug = 0;
  31. - int            autoRepeatReady;
  32. - long            autoRepeatInitiate = 1000 * AUTOREPEAT_INITIATE;
  33. - long            autoRepeatDelay = 1000 * AUTOREPEAT_DELAY;
  34. - static int      autoRepeatFirst;
  35. - struct timeval    autoRepeatLastKeyDownTv;
  36. - struct timeval    autoRepeatDeltaTv;
  37.   static KeybdCtrl  sysKbCtrl;
  38.   
  39.   static SunKbPrivRec    sunKbPriv;  
  40. --- 47,98 ----
  41.   #endif
  42.   
  43.   
  44. + #define Time SpriteTime
  45. + #include <fs.h>
  46. + #undef Time
  47.   #define NEED_EVENTS
  48.   #include "sun.h"
  49. ! #include <bit.h>
  50. ! #include <errno.h>
  51. ! #include <fcntl.h>
  52. ! #include <sys/file.h>
  53. ! #include <sys/time.h>
  54.   #include "keysym.h"
  55. ! #include "keymap.h"
  56.   
  57. + #define AUTO_GENERATED    0x10000
  58. + #define MIN_KEYCODE    8       /* Keycode below which we may not transmit */
  59. + #define ALL_KEYS_UP    127    /* all keys are up now */
  60. + /*
  61. +  * Auto-repeat stuff.
  62. +  */
  63. + static enum {
  64. +     REPEAT_LONG,        /* Start repeat with long timeout */
  65. +     REPEAT_SHORT,        /* Start repeat with short timeout */
  66. +     REPEAT_TIMEOUT,        /* In the middle of a timeout */
  67. +     REPEAT_PENDING,        /* Repeat should be taken next */
  68. +     REPEAT_NONE              /* No repeat should happen */
  69. + } repeatPhase = REPEAT_NONE;
  70. + static Mouse_Event    repeatEvent;    /* Event that will be repeated */
  71. + static struct timeval     repeatTimeout;    /* Timeout to use for repeating */
  72. + static unsigned int    repeatDelta;    /* Timeout length (ms) */
  73. + /* The following two are set in sunIo.c */
  74. + unsigned int        repeatLong=300;    /* Ms delay to begin repeat */
  75. + unsigned int        repeatShort=10;    /* Ms delay to begin repeat */
  76.   typedef struct {
  77.       int              trans;              /* Original translation form */
  78.   } SunKbPrivRec, *SunKbPrivPtr;
  79.   
  80.   extern void    ProcessInputEvents();
  81.   extern void    miPointerPosition();
  82.   
  83.   static void       sunBell();
  84.   static void       sunKbdCtrl();
  85. ! static Mouse_Event *sunKbdGetEvents();
  86.   static void       sunKbdProcessEvent();
  87.   static void       sunKbdDoneEvents();
  88.   static KeybdCtrl  sysKbCtrl;
  89.   
  90.   static SunKbPrivRec    sunKbPriv;  
  91. ***************
  92. *** 88,94 ****
  93.       sunKbdDoneEvents,        /* Function called when all events */
  94.                   /* have been handled. */
  95.       (pointer)&sunKbPriv,    /* Private to keyboard device */
  96. -     (Bool)0,            /* Mapped queue */
  97.       0,                /* offset for device keycodes */
  98.       &sysKbCtrl,            /* Initial full duration = .25 sec. */
  99.   };
  100. --- 104,109 ----
  101. ***************
  102. *** 119,128 ****
  103.   {
  104.       KbPrivPtr      pPriv;
  105.       register int  kbdFd;
  106. - #ifdef    SUN_WINDOWS
  107. - #define    TR_UNDEFINED (TR_NONE-1)
  108. -     static int      deviceOffKbdState = TR_UNDEFINED;
  109. - #endif    SUN_WINDOWS
  110.   
  111.       switch (what) {
  112.       case DEVICE_INIT:
  113. --- 134,139 ----
  114. ***************
  115. *** 134,191 ****
  116.           /*
  117.            * First open and find the current state of the keyboard.
  118.            */
  119. ! /*
  120. !  * The Sun 386i has system include files that preclude this pre SunOS 4.1
  121. !  * test for the presence of a type 4 keyboard however it really doesn't
  122. !  * matter since no 386i has ever been shipped with a type 3 keyboard.
  123. !  */
  124. ! #ifndef i386
  125. ! #define TYPE4KEYBOARDOVERRIDE
  126. ! #endif
  127. !         if (sysKbPriv.fd >= 0) {
  128. !         kbdFd = sysKbPriv.fd;
  129. !         } else {
  130. !         kbdFd = open ("/dev/kbd", O_RDWR, 0);
  131. !         if (kbdFd < 0) {
  132. !             Error ("Opening /dev/kbd");
  133.               return (!Success);
  134.           }
  135. -         sysKbPriv.fd = kbdFd;
  136. -         (void) ioctl (kbdFd, KIOCTYPE, &sysKbPriv.type);
  137. -         (void) ioctl (kbdFd, KIOCGTRANS, &sunKbPriv.trans);
  138. - #ifdef TYPE4KEYBOARDOVERRIDE
  139. -                 /*
  140. -                  * Magic. Look for a key which is non-existent on a real type
  141. -                  * 3 keyboard but does exist on a type 4 keyboard.
  142. -                  */
  143. -                 if (sysKbPriv.type == KB_SUN3) {
  144. -                     struct kiockey key;
  145. -                     key.kio_tablemask = 0;
  146. -                     key.kio_station = 118;
  147. -                     if (ioctl(kbdFd, KIOCGETKEY, &key)) {
  148. -                         perror( "ioctl KIOCGETKEY" );
  149. -             FatalError("Can't KIOCGETKEY on fd %d\n", kbdFd);
  150. -                     }
  151. -                     if (key.kio_entry != HOLE)
  152. -                         sysKbPriv.type = KB_SUN4;
  153. -                 }
  154. - #endif
  155. -         if (sysKbPriv.type < 0 || sysKbPriv.type > KB_SUN4
  156. -             || sunKeySyms[sysKbPriv.type].map == NULL)
  157. -             FatalError("Unsupported keyboard type %d\n", 
  158. -             sysKbPriv.type);
  159. -         if (sunUseSunWindows()) {
  160. -             (void) close( kbdFd );
  161. -             sysKbPriv.fd = -1;
  162. -         } else {
  163. -             if (fcntl (kbdFd, F_SETFL, (FNDELAY|FASYNC)) < 0
  164. -             || fcntl(kbdFd, F_SETOWN, getpid()) < 0) {
  165. -             perror("sunKbdProc");
  166. -             FatalError("Can't set up kbd on fd %d\n", kbdFd);
  167. -             }
  168. -         }
  169.           }
  170.   
  171.           /*
  172. --- 145,160 ----
  173.           /*
  174.            * First open and find the current state of the keyboard.
  175.            */
  176. !         if (sysKbPriv.fd < 0) {
  177. !             ReturnStatus status;
  178. !         status = Fs_Open("/dev/mouse",
  179. !             FS_NON_BLOCKING|FS_READ|FS_WRITE, 0, &sysKbPriv.fd);
  180. !             if (status != 0) {
  181. !             errno = Compat_MapCode(status);
  182. !             Error ("Opening /dev/mouse");
  183.               return (!Success);
  184.           }
  185.           }
  186.   
  187.           /*
  188. ***************
  189. *** 201,307 ****
  190.           /*
  191.            * ensure that the keycodes on the wire are >= MIN_KEYCODE
  192.            */
  193. !         if (sunKeySyms[sysKbPriv.type].minKeyCode < MIN_KEYCODE) {
  194. !         int offset = MIN_KEYCODE -sunKeySyms[sysKbPriv.type].minKeyCode;
  195.   
  196. !         sunKeySyms[sysKbPriv.type].minKeyCode += offset;
  197. !         sunKeySyms[sysKbPriv.type].maxKeyCode += offset;
  198. !         sysKbPriv.offset = offset;
  199. !         }
  200. !         InitKeyboardDeviceStruct(
  201. !             pKeyboard,
  202. !             &(sunKeySyms[sysKbPriv.type]),
  203. !             (sunModMap[sysKbPriv.type]),
  204. !             sunBell,
  205. !             sunKbdCtrl);
  206.           break;
  207.   
  208.       case DEVICE_ON:
  209. !         if (sunUseSunWindows()) {
  210. ! #ifdef SUN_WINDOWS
  211. !         if (! sunSetUpKbdSunWin(windowFd, TRUE)) {
  212. !             FatalError("Can't set up keyboard\n");
  213. !         }
  214. !         /*
  215. !          * Don't tamper with keyboard translation here
  216. !          * unless this is a server reset.  If server
  217. !          * is reset then set translation to that saved
  218. !          * when DEVICE_CLOSE was executed.
  219. !          * Translation is set/reset upon receipt of
  220. !          * KBD_USE/KBD_DONE input events (sunIo.c)
  221. !          */
  222. !         if (deviceOffKbdState != TR_UNDEFINED) {
  223. !             if (sunChangeKbdTranslation(pKeyboard,
  224. !                 deviceOffKbdState == TR_UNTRANS_EVENT) < 0) {
  225. !             FatalError("Can't set (SW) keyboard translation\n");
  226. !             }
  227. !         }
  228. !         AddEnabledDevice(windowFd);
  229. ! #endif SUN_WINDOWS
  230. !         }
  231. !         else {
  232. !         pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  233. !         kbdFd = pPriv->fd;
  234. !             /*
  235. !              * Set the keyboard into "direct" mode and turn on
  236. !              * event translation.
  237. !              */
  238. !         if (sunChangeKbdTranslation(pKeyboard,TRUE) < 0) {
  239. !             FatalError("Can't set keyboard translation\n");
  240. !         }
  241. !         AddEnabledDevice(kbdFd);
  242. !         }
  243.           pKeyboard->on = TRUE;
  244.           break;
  245.   
  246.       case DEVICE_CLOSE:
  247.       case DEVICE_OFF:
  248. !         if (sunUseSunWindows()) {
  249. ! #ifdef SUN_WINDOWS
  250. !         /*
  251. !          * Save current translation state in case of server
  252. !          * reset.  Used above when DEVICE_ON is executed.
  253. !          */
  254. !         if ((kbdFd = open("/dev/kbd", O_RDONLY, 0)) < 0) {
  255. !             Error("DEVICE_OFF: Can't open kbd\n");
  256. !             goto badkbd;
  257. !         }
  258. !         if (ioctl(kbdFd, KIOCGTRANS, &deviceOffKbdState) < 0) {
  259. !             Error("Can't save keyboard state\n");
  260. !         }
  261. !         (void) close(kbdFd);
  262. ! badkbd:
  263. !         if (! sunSetUpKbdSunWin(windowFd, FALSE)) {
  264. !             FatalError("Can't close keyboard\n");
  265. !         }
  266. !         /*
  267. !          * Restore SunWindows translation.
  268. !          */
  269. !         if (sunChangeKbdTranslation(pKeyboard,FALSE) < 0) {
  270. !             FatalError("Can't reset keyboard translation\n");
  271. !         }
  272. !         RemoveEnabledDevice(windowFd);
  273. ! #endif SUN_WINDOWS
  274. !         }
  275. !         else {
  276. !         pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  277. !         kbdFd = pPriv->fd;
  278. !             /*
  279. !              * Restore original keyboard directness and translation.
  280. !              */
  281. !         if (sunChangeKbdTranslation(pKeyboard,FALSE) < 0) {
  282. !             FatalError("Can't reset keyboard translation\n");
  283. !         }
  284. !         RemoveEnabledDevice(kbdFd);
  285. !         }
  286.           pKeyboard->on = FALSE;
  287.           break;
  288.       }
  289.       return (Success);
  290. --- 170,202 ----
  291.           /*
  292.            * ensure that the keycodes on the wire are >= MIN_KEYCODE
  293.            */
  294. !          if (sunMapDesc.minKeyCode < MIN_KEYCODE) {
  295. !          int    offset;
  296.   
  297. !          offset = MIN_KEYCODE - sunMapDesc.minKeyCode;
  298. !          sunMapDesc.minKeyCode += offset;
  299. !          sunMapDesc.maxKeyCode += offset;
  300. !          sysKbPriv.offset = offset;
  301. !          }
  302. !         InitKeyboardDeviceStruct(pKeyboard, &sunMapDesc, sunModMap,
  303. !                      sunBell, sunKbdCtrl);
  304.           break;
  305.   
  306.       case DEVICE_ON:
  307. !         pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  308. !         kbdFd = pPriv->fd;
  309. !         AddEnabledDevice(kbdFd);
  310.           pKeyboard->on = TRUE;
  311. +         repeatPhase = REPEAT_NONE;
  312.           break;
  313.   
  314.       case DEVICE_CLOSE:
  315.       case DEVICE_OFF:
  316. !         pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  317. !         kbdFd = pPriv->fd;
  318. !         RemoveEnabledDevice(kbdFd);
  319.           pKeyboard->on = FALSE;
  320. +         repeatPhase = REPEAT_NONE;
  321.           break;
  322.       }
  323.       return (Success);
  324. ***************
  325. *** 326,371 ****
  326.       int              loudness;        /* Percentage of full volume */
  327.       DevicePtr      pKeyboard;        /* Keyboard to ring */
  328.   {
  329. !     KbPrivPtr      pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  330. !     int            kbdCmd;           /* Command to give keyboard */
  331. !     int           kbdOpenedHere; 
  332. !  
  333.       if (loudness == 0) {
  334. !      return;
  335.       }
  336.   
  337. !     kbdOpenedHere = ( pPriv->fd < 0 );
  338. !     if ( kbdOpenedHere ) {
  339. !     pPriv->fd = open("/dev/kbd", O_RDWR, 0);
  340. !     if (pPriv->fd < 0) {
  341. !         ErrorF("sunBell: can't open keyboard");
  342. !         return;
  343. !     }
  344. !     }    
  345. !  
  346. !     kbdCmd = KBD_CMD_BELL;
  347. !     if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) < 0) {
  348. !      ErrorF ("Failed to activate bell");
  349. !     goto bad;
  350. !     }
  351. !  
  352. !     /*
  353. !      * Leave the bell on for a while == duration (ms) proportional to
  354. !      * loudness desired with a 10 thrown in to convert from ms to usecs.
  355. !      */
  356. !     usleep (pPriv->ctrl->bell_duration * 1000);
  357. !  
  358. !     kbdCmd = KBD_CMD_NOBELL;
  359. !     if (ioctl (pPriv->fd, KIOCCMD, &kbdCmd) < 0) {
  360. !     ErrorF ("Failed to deactivate bell");
  361. !     goto bad;
  362. !     }
  363. ! bad:
  364. !     if ( kbdOpenedHere ) {
  365. !     (void) close(pPriv->fd);
  366. !     pPriv->fd = -1;
  367. !     }
  368.   }
  369.   
  370.   /*-
  371. --- 221,247 ----
  372.       int              loudness;        /* Percentage of full volume */
  373.       DevicePtr      pKeyboard;        /* Keyboard to ring */
  374.   {
  375. !     KbPrivPtr        pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  376. !     char        kbdCmd;
  377. !     struct timeval    sleepTime;
  378.       if (loudness == 0) {
  379. !     return;
  380.       }
  381.   
  382. !     kbdCmd = KBD_BELL_ON;
  383. !     (void) write(pPriv->fd, &kbdCmd, 1);
  384. !     sleepTime.tv_usec = pPriv->ctrl->bell_duration * 1000;
  385. !     sleepTime.tv_sec = 0;
  386. !     while (sleepTime.tv_usec >= 1000000) {
  387. !     sleepTime.tv_sec += 1;
  388. !     sleepTime.tv_usec -= 1000000;
  389. !     }
  390. !     (void) select(0, (int *) 0, (int *) 0, (int *) 0, &sleepTime);
  391. !     kbdCmd = KBD_BELL_OFF;
  392. !     (void) write(pPriv->fd, &kbdCmd, 1);
  393.   }
  394.   
  395.   /*-
  396. ***************
  397. *** 386,415 ****
  398.       DevicePtr      pKeyboard;        /* Keyboard to alter */
  399.       KeybdCtrl     *ctrl;
  400.   {
  401. !     KbPrivPtr      pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  402. !     int           kbdClickCmd = ctrl->click ? KBD_CMD_CLICK : KBD_CMD_NOCLICK;
  403. !     int           kbdOpenedHere; 
  404.   
  405. !     kbdOpenedHere = ( pPriv->fd < 0 );
  406. !     if ( kbdOpenedHere ) {
  407. !     pPriv->fd = open("/dev/kbd", O_WRONLY, 0);
  408. !     if (pPriv->fd < 0) {
  409. !         ErrorF("sunKbdCtrl: can't open keyboard");
  410. !         return;
  411. !     }
  412. !     }
  413.   
  414. !     if (ioctl (pPriv->fd, KIOCCMD, &kbdClickCmd) < 0) {
  415. !      ErrorF("Failed to set keyclick");
  416. !     goto bad;
  417.       }
  418. !  
  419. !     *pPriv->ctrl = *ctrl;
  420. ! bad:
  421. !     if ( kbdOpenedHere ) {
  422. !     (void) close(pPriv->fd);
  423. !     pPriv->fd = -1;
  424.       }
  425.   }
  426.   
  427. --- 262,283 ----
  428.       DevicePtr      pKeyboard;        /* Keyboard to alter */
  429.       KeybdCtrl     *ctrl;
  430.   {
  431. !     KbPrivPtr      pPriv;
  432. !     char      kbCmd;
  433.   
  434. !     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  435.   
  436. !     pPriv->ctrl = ctrl;
  437. !     if (ctrl->click) {
  438. !     kbCmd = KBD_CLICK_ON;
  439. !     } else {
  440. !     kbCmd = KBD_CLICK_OFF;
  441.       }
  442. !     (void) write(pPriv->fd, &kbCmd, 1);
  443. !     if (!ctrl->autoRepeat) {
  444. !     repeatPhase = REPEAT_NONE;
  445.       }
  446.   }
  447.   
  448. ***************
  449. *** 432,470 ****
  450.    *    None.
  451.    *-----------------------------------------------------------------------
  452.    */
  453. ! static Firm_event *
  454. ! sunKbdGetEvents (pKeyboard, pNumEvents, pAgain)
  455.       DevicePtr      pKeyboard;        /* Keyboard to read */
  456.       int              *pNumEvents;        /* Place to return number of events */
  457. -     Bool      *pAgain;        /* whether more might be available */
  458.   {
  459.       int              nBytes;        /* number of bytes of events available. */
  460.       KbPrivPtr      pPriv;
  461. !     static Firm_event    evBuf[MAXEVENTS];   /* Buffer for Firm_events */
  462.   
  463. !     pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  464. !     nBytes = read (pPriv->fd, evBuf, sizeof(evBuf));
  465.   
  466. !     if (nBytes < 0) {
  467. !     if (errno == EWOULDBLOCK) {
  468. !         *pNumEvents = 0;
  469. !         *pAgain = FALSE;
  470. !     } else {
  471. !         Error ("Reading keyboard");
  472. !         FatalError ("Could not read the keyboard");
  473. !     }
  474. !     } else {
  475. !     *pNumEvents = nBytes / sizeof (Firm_event);
  476. !     *pAgain = (nBytes == sizeof (evBuf));
  477. !     }
  478.   
  479. !     if (autoRepeatKeyDown && autoRepeatReady &&
  480. !          pPriv->ctrl->autoRepeat == AutoRepeatModeOn && *pNumEvents == 0) {
  481. !     *pNumEvents = 1;            /* Fake the event */
  482. !     evBuf[0].id = AUTOREPEAT_EVENTID;    /* Flags autoRepeat event */
  483. !     if (autoRepeatDebug)
  484. !         ErrorF("sunKbdGetEvents: autoRepeatKeyDown = %d event\n",
  485. !                 autoRepeatKeyDown);
  486.       }
  487.   
  488.       return (evBuf);
  489. --- 300,344 ----
  490.    *    None.
  491.    *-----------------------------------------------------------------------
  492.    */
  493. ! static Mouse_Event *
  494. ! sunKbdGetEvents (pKeyboard, pNumEvents)
  495.       DevicePtr      pKeyboard;        /* Keyboard to read */
  496.       int              *pNumEvents;        /* Place to return number of events */
  497.   {
  498.       int              nBytes;        /* number of bytes of events available. */
  499.       KbPrivPtr      pPriv;
  500. !     static Mouse_Event    evBuf[MAXEVENTS];   /* Buffer for Firm_events */
  501.   
  502. !     if (repeatPhase == REPEAT_PENDING) {
  503. !     /*
  504. !      * This will only have been set if no streams were really ready, thus
  505. !      * there are no events to read from /dev/mouse.
  506. !      */
  507. !     repeatEvent.flags |= KEY_UP;
  508. !     repeatEvent.time += repeatDelta / 2;
  509. !     evBuf[0] = repeatEvent;
  510.   
  511. !     repeatEvent.flags &= ~KEY_UP;
  512. !     repeatEvent.time += repeatDelta / 2;
  513. !     evBuf[1] = repeatEvent;
  514. !     *pNumEvents = 2;
  515.   
  516. !     repeatPhase = REPEAT_SHORT;
  517. !     } else {
  518. !         pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  519. !         nBytes = read (pPriv->fd, evBuf, sizeof(evBuf));
  520. !     
  521. !         if (nBytes < 0) {
  522. !         if (errno == EWOULDBLOCK) {
  523. !             *pNumEvents = 0;
  524. !         } else {
  525. !             Error ("Reading keyboard");
  526. !             FatalError ("Could not read the keyboard");
  527. !             }
  528. !         } else {
  529. !         *pNumEvents = nBytes / sizeof (Mouse_Event);
  530. !         }
  531.       }
  532.   
  533.       return (evBuf);
  534. ***************
  535. *** 490,579 ****
  536.    *-----------------------------------------------------------------------
  537.    */
  538.   static void
  539. ! sunKbdProcessEvent (pKeyboard, fe)
  540.       DevicePtr      pKeyboard;
  541. !     Firm_event      *fe;
  542.   {
  543.       xEvent        xE;
  544. !     KbPrivPtr        pPriv;
  545. !     int            delta;
  546. !     static xEvent    autoRepeatEvent;
  547. !     BYTE        key;
  548. !     CARD8        keyModifiers;
  549. !     if (autoRepeatKeyDown && fe->id == AUTOREPEAT_EVENTID) {
  550. !     pPriv = (KbPrivPtr) pKeyboard->devicePrivate;
  551. !     if (pPriv->ctrl->autoRepeat != AutoRepeatModeOn) {
  552. !         autoRepeatKeyDown = 0;
  553. !         return;
  554. !     }
  555. !     /*
  556. !      * Generate auto repeat event.    XXX one for now.
  557. !      * Update time & pointer location of saved KeyPress event.
  558. !      */
  559. !     if (autoRepeatDebug)
  560. !         ErrorF("sunKbdProcessEvent: autoRepeatKeyDown = %d\n",
  561. !             autoRepeatKeyDown);
  562.   
  563. !     delta = TVTOMILLI(autoRepeatDeltaTv);
  564. !     autoRepeatFirst = FALSE;
  565. !     /*
  566. !      * Fake a key up event and a key down event
  567. !      * for the last key pressed.
  568. !      */
  569. !     autoRepeatEvent.u.keyButtonPointer.time += delta;
  570. !     miPointerPosition (screenInfo.screens[0],
  571. !                &autoRepeatEvent.u.keyButtonPointer.rootX,
  572. !                &autoRepeatEvent.u.keyButtonPointer.rootY);
  573. !     autoRepeatEvent.u.u.type = KeyRelease;
  574. !     (* pKeyboard->processInputProc) (&autoRepeatEvent, pKeyboard, 1);
  575. !     autoRepeatEvent.u.u.type = KeyPress;
  576. !     (* pKeyboard->processInputProc) (&autoRepeatEvent, pKeyboard, 1);
  577. !     /* Update time of last key down */
  578. !     tvplus(autoRepeatLastKeyDownTv, autoRepeatLastKeyDownTv, 
  579. !             autoRepeatDeltaTv);
  580. !     return;
  581. !     }
  582.   
  583. !     key = (fe->id & 0x7F) + sysKbPriv.offset;
  584. !     keyModifiers = ((DeviceIntPtr)pKeyboard)->key->modifierMap[key];
  585. !     if (autoRepeatKeyDown && (keyModifiers == 0) &&
  586. !     ((fe->value == VKEY_DOWN) || (key == autoRepeatEvent.u.u.detail))) {
  587. !     /*
  588. !      * Kill AutoRepeater on any real non-modifier key down, or auto key up
  589. !      */
  590. !     autoRepeatKeyDown = 0;
  591. !     if (autoRepeatDebug)
  592. !         ErrorF("sunKbdProcessEvent: autoRepeat off\n");
  593.       }
  594. -     xE.u.keyButtonPointer.time = TVTOMILLI(fe->time);
  595.       miPointerPosition (screenInfo.screens[0],
  596.                  &xE.u.keyButtonPointer.rootX,
  597.                  &xE.u.keyButtonPointer.rootY);
  598. -     xE.u.u.type = ((fe->value == VKEY_UP) ? KeyRelease : KeyPress);
  599. -     xE.u.u.detail = key;
  600. -     if (keyModifiers & LockMask) {
  601. -     if (xE.u.u.type == KeyRelease)
  602. -         return; /* this assumes autorepeat is not desired */
  603. -     if (BitIsOn(((DeviceIntPtr)pKeyboard)->key->down, key))
  604. -         xE.u.u.type = KeyRelease;
  605. -     }
  606. -     if ((xE.u.u.type == KeyPress) && (keyModifiers == 0)) {
  607. -     /* initialize new AutoRepeater event & mark AutoRepeater on */
  608. -     if (autoRepeatDebug)
  609. -             ErrorF("sunKbdProcessEvent: VKEY_DOWN\n");
  610. -     autoRepeatEvent = xE;
  611. -     autoRepeatFirst = TRUE;
  612. -     autoRepeatKeyDown++;
  613. -     autoRepeatLastKeyDownTv = fe->time;
  614. -     }
  615.   
  616.       (* pKeyboard->processInputProc) (&xE, pKeyboard, 1);
  617.   }
  618. --- 364,410 ----
  619.    *-----------------------------------------------------------------------
  620.    */
  621.   static void
  622. ! sunKbdProcessEvent (pKeyboard, ev)
  623.       DevicePtr      pKeyboard;
  624. !     Mouse_Event      *ev;
  625.   {
  626.       xEvent        xE;
  627. !     register KbPrivPtr    pPriv;
  628. !     register int      smask;
  629. !     PtrPrivPtr          ptrPriv;
  630.   
  631. !     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  632. !     ptrPriv = (PtrPrivPtr) LookupPointerDevice()->devicePrivate;
  633.   
  634. !     xE.u.keyButtonPointer.time = ev->time;
  635. !     xE.u.u.detail = ev->key + pPriv->offset;
  636. !     if (ev->key == ALL_KEYS_UP) {
  637. !     xE.u.u.type = KeyRelease;
  638. !     repeatPhase = REPEAT_NONE;
  639. !     } else if (ev->flags & KEY_UP) {
  640. !     xE.u.u.type = KeyRelease;
  641. !     if (!(ev->flags & AUTO_GENERATED) &&
  642. !          (repeatPhase != REPEAT_NONE) &&
  643. !          (repeatEvent.key == ev->key)) {
  644. !         /*
  645. !          * Turn off repeat if we got a real up event for the key
  646. !          * being repeated
  647. !          */
  648. !         repeatPhase = REPEAT_NONE;
  649. !     }
  650. !     } else {
  651. !     xE.u.u.type = KeyPress;
  652. !     if ((repeatPhase != REPEAT_SHORT) &&
  653. !         (pPriv->ctrl->autoRepeat ||
  654. !          Bit_IsSet (xE.u.u.detail, pPriv->ctrl->autoRepeats))) {
  655. !          repeatEvent = *ev;
  656. !          repeatEvent.flags |= AUTO_GENERATED;
  657. !          repeatPhase = REPEAT_LONG;
  658. !     }
  659.       }
  660.       miPointerPosition (screenInfo.screens[0],
  661.                  &xE.u.keyButtonPointer.rootX,
  662.                  &xE.u.keyButtonPointer.rootY);
  663.   
  664.       (* pKeyboard->processInputProc) (&xE, pKeyboard, 1);
  665.   }
  666. ***************
  667. *** 598,875 ****
  668.   
  669.   /*-
  670.    *-----------------------------------------------------------------------
  671. !  * sunChangeKbdTranslation
  672. !  *    Makes operating system calls to set keyboard translation 
  673. !  *    and direction on or off.
  674.    *
  675.    * Results:
  676. !  *    -1 if failure, else 0.
  677. !  *
  678. !  * Side Effects:
  679. !  *     Changes kernel management of keyboard.
  680.    *
  681. -  *-----------------------------------------------------------------------
  682. -  */
  683. - int
  684. - sunChangeKbdTranslation(pKeyboard,makeTranslated)
  685. -     DevicePtr pKeyboard;
  686. -     Bool makeTranslated;
  687. - {   
  688. -     KbPrivPtr    pPriv;
  689. -     int     kbdFd;
  690. -     int     tmp;
  691. -     int        kbdOpenedHere;
  692. -     static struct timeval lastChngKbdTransTv;
  693. -     struct timeval tv;
  694. -     struct timeval lastChngKbdDeltaTv;
  695. -     int lastChngKbdDelta;
  696. -     /*
  697. -      * Workaround for SS1 serial driver kernel bug when KIOCTRANS ioctl()s
  698. -      * occur too closely together in time.
  699. -      */
  700. -     gettimeofday(&tv, (struct timezone *) NULL);
  701. -     tvminus(lastChngKbdDeltaTv, tv, lastChngKbdTransTv);
  702. -     lastChngKbdDelta = TVTOMILLI(lastChngKbdDeltaTv);
  703. -     if (lastChngKbdDelta < 750) {
  704. -     struct timeval wait;
  705. -     /*
  706. -          * We need to guarantee at least 750 milliseconds between
  707. -      * calls to KIOCTRANS. YUCK!
  708. -      */
  709. -     wait.tv_sec = 0;
  710. -     wait.tv_usec = (750L - lastChngKbdDelta) * 1000L;
  711. -         (void) select(0, (int *)0, (int *)0, (int *)0, &wait);
  712. -         gettimeofday(&tv, (struct timezone *) NULL);
  713. -     }
  714. -     lastChngKbdTransTv = tv;
  715. -     
  716. -     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  717. -     kbdFd = pPriv->fd;
  718. -     kbdOpenedHere = ( kbdFd < 0 );
  719. -     if ( kbdOpenedHere ) {
  720. -     kbdFd = open("/dev/kbd", O_RDONLY, 0);
  721. -     if ( kbdFd < 0 ) {
  722. -         Error( "sunChangeKbdTranslation: Can't open keyboard" );
  723. -         goto bad;
  724. -     }
  725. -     }
  726. -     
  727. -     if (makeTranslated) {
  728. -         /*
  729. -          * Next set the keyboard into "direct" mode and turn on
  730. -          * event translation. If either of these fails, we can't go
  731. -          * on.
  732. -          */
  733. -     if ( ! sunUseSunWindows() ) {
  734. -         tmp = 1;
  735. -         if (ioctl (kbdFd, KIOCSDIRECT, &tmp) < 0) {
  736. -         Error ("Setting keyboard direct mode");
  737. -         goto bad;
  738. -         }
  739. -     }
  740. -     tmp = TR_UNTRANS_EVENT;
  741. -     if (ioctl (kbdFd, KIOCTRANS, &tmp) < 0) {
  742. -         ErrorF("sunChangeKbdTranslation: kbdFd=%d\n",kbdFd);
  743. -         Error ("Setting keyboard translation");
  744. -         goto bad;
  745. -     }
  746. -     }
  747. -     else {
  748. -         /*
  749. -          * Next set the keyboard into "indirect" mode and turn off
  750. -          * event translation.
  751. -          */
  752. -     if ( ! sunUseSunWindows() ) {
  753. -         tmp = 0;
  754. -         (void)ioctl (kbdFd, KIOCSDIRECT, &tmp);
  755. -     }
  756. -     tmp = ((SunKbPrivPtr)pPriv->devPrivate)->trans;
  757. -     (void)ioctl (kbdFd, KIOCTRANS, &tmp);
  758. -     }
  759. -     if ( kbdOpenedHere )
  760. -     (void) close( kbdFd );
  761. -     return(0);
  762. - bad:
  763. -     if ( kbdOpenedHere && kbdFd >= 0 )
  764. -     (void) close( kbdFd );
  765. -     return(-1);
  766. - }
  767. - #ifdef SUN_WINDOWS
  768. - /*-
  769. -  *-----------------------------------------------------------------------
  770. -  * sunSetUpKbdSunWin
  771. -  *    Change which events the kernel will pass through as keyboard
  772. -  *     events.
  773. -  *
  774. -  *    Does NOT affect keyboard translation.
  775. -  *
  776. -  * Results:
  777. -  *    Inputevent mask modified.
  778. -  *
  779.    * Side Effects:
  780.    *
  781.    *-----------------------------------------------------------------------
  782.    */
  783.   Bool
  784. ! sunSetUpKbdSunWin(windowFd, onoff)
  785. !     int windowFd;
  786. !     Bool onoff;
  787.   {
  788. -     struct inputmask inputMask;
  789. -     static struct inputmask oldInputMask;
  790. -     if (onoff) {
  791. -         register int i;
  792. -     win_get_kbd_mask(windowFd, &oldInputMask);
  793. -     input_imnull(&inputMask);
  794. -     inputMask.im_flags |= 
  795. -         IM_ASCII | IM_NEGASCII | 
  796. -         IM_META | IM_NEGMETA | 
  797. -         IM_NEGEVENT | IM_INTRANSIT;
  798. -     win_setinputcodebit(&inputMask, KBD_USE);
  799. -     win_setinputcodebit(&inputMask, KBD_DONE);
  800. -     win_setinputcodebit(&inputMask, SHIFT_CAPSLOCK);
  801. -     win_setinputcodebit(&inputMask, SHIFT_LOCK);
  802. -     win_setinputcodebit(&inputMask, SHIFT_LEFT);
  803. -     win_setinputcodebit(&inputMask, SHIFT_RIGHT);
  804. -     win_setinputcodebit(&inputMask, SHIFT_LEFTCTRL);
  805. -     win_setinputcodebit(&inputMask, SHIFT_RIGHTCTRL);
  806. -     win_setinputcodebit(&inputMask, SHIFT_META);
  807. -     win_setinputcodebit(&inputMask, WIN_STOP);
  808. -         for (i=KEY_LEFTFIRST; i<=KEY_LEFTLAST; i++) {
  809. -             win_setinputcodebit(&inputMask, i);
  810. -         }
  811. -         for (i=KEY_TOPFIRST; i<=KEY_TOPLAST; i++) {
  812. -             win_setinputcodebit(&inputMask, i);
  813. -         }
  814. -         for (i=KEY_RIGHTFIRST; i<=KEY_RIGHTLAST; i++) {
  815. -             win_setinputcodebit(&inputMask, i);
  816. -         }
  817. -     win_set_kbd_mask(windowFd, &inputMask);
  818. -     }
  819. -     else {
  820. -     win_set_kbd_mask(windowFd, &oldInputMask);
  821. -     }
  822.       return (TRUE);
  823.   }
  824.   
  825. ! #endif SUN_WINDOWS
  826. ! #ifdef SUN_WINDOWS
  827.   
  828.   /*-
  829.    *-----------------------------------------------------------------------
  830. !  * sunKbdProcessEventSunWin
  831. !  *    Process sunwindows event destined for the keyboard.
  832. !  *      Rather than replicate the logic (and therefore replicate
  833. !  *     bug fixes, etc), this code counterfeits a vuid 
  834. !  *    Firm_event and then uses the non-sunwindows code.
  835. !  *     
  836.    * Results:
  837.    *
  838.    * Side Effects:
  839.    *
  840.    *-----------------------------------------------------------------------
  841.    */
  842. - void
  843. - sunKbdProcessEventSunWin(pKeyboard,se)
  844. -     DeviceRec *pKeyboard;
  845. -     register struct inputevent *se;
  846. - {   
  847. -     Firm_event    fe;
  848. -     fe.time = event_time(se);
  849. -     fe.id = event_id(se);
  850. -     fe.value = (event_is_up(se) ? VKEY_UP : VKEY_DOWN);
  851. -     sunKbdProcessEvent (pKeyboard, &fe);
  852. - }
  853. - #endif SUN_WINDOWS
  854. - /*ARGSUSED*/
  855. - Bool
  856. - LegalModifier(key)
  857. - {
  858. -     return (TRUE);
  859. - }
  860. - static KeybdCtrl *pKbdCtrl = (KeybdCtrl *) 0;
  861. - /*ARGSUSED*/
  862.   void
  863. ! sunBlockHandler(nscreen, pbdata, pptv, pReadmask)
  864. !     int nscreen;
  865. !     pointer pbdata;
  866. !     struct timeval **pptv;
  867. !     pointer pReadmask;
  868.   {
  869. !     static struct timeval artv = { 0, 0 };    /* autorepeat timeval */
  870. !     if (!autoRepeatKeyDown)
  871.       return;
  872. !     if (pKbdCtrl == (KeybdCtrl *) 0)
  873. !     pKbdCtrl = ((KbPrivPtr) LookupKeyboardDevice()->devicePrivate)->ctrl;
  874. !     if (pKbdCtrl->autoRepeat != AutoRepeatModeOn)
  875.       return;
  876. !     if (autoRepeatFirst == TRUE)
  877. !     artv.tv_usec = autoRepeatInitiate;
  878. !     else
  879. !     artv.tv_usec = autoRepeatDelay;
  880. !     *pptv = &artv;
  881. !     if (autoRepeatDebug)
  882. !     ErrorF("sunBlockHandler(%d,%d): \n", artv.tv_sec, artv.tv_usec);
  883.   }
  884. ! /*ARGSUSED*/
  885.   void
  886. ! sunWakeupHandler(nscreen, pbdata, err, pReadmask)
  887. !     int nscreen;
  888. !     pointer pbdata;
  889. !     unsigned long err;
  890. !     pointer pReadmask;
  891. ! {
  892. !     struct timeval tv;
  893. !     if (autoRepeatDebug)
  894. !     ErrorF("sunWakeupHandler(ar=%d, err=%d):\n", autoRepeatKeyDown, err);
  895. !     if (pKbdCtrl == (KeybdCtrl *) 0)
  896. !     pKbdCtrl = ((KbPrivPtr) LookupKeyboardDevice()->devicePrivate)->ctrl;
  897. !     if (pKbdCtrl->autoRepeat != AutoRepeatModeOn)
  898. !     return;
  899.   
  900. !     if (autoRepeatKeyDown) {
  901. !     gettimeofday(&tv, (struct timezone *) NULL);
  902. !     tvminus(autoRepeatDeltaTv, tv, autoRepeatLastKeyDownTv);
  903. !     if (autoRepeatDeltaTv.tv_sec > 0 ||
  904. !             (!autoRepeatFirst && autoRepeatDeltaTv.tv_usec >
  905. !                 autoRepeatDelay) ||
  906. !             (autoRepeatDeltaTv.tv_usec >
  907. !                 autoRepeatInitiate))
  908. !         autoRepeatReady++;
  909. !     }
  910.       
  911. !     if (autoRepeatReady)
  912.       ProcessInputEvents();
  913. !     autoRepeatReady = 0;
  914.   }
  915. --- 429,533 ----
  916.   
  917.   /*-
  918.    *-----------------------------------------------------------------------
  919. !  * LegalModifier --
  920. !  *    See if a key is legal as a modifier. We're very lenient around,
  921. !  *    here, so we always return true.
  922.    *
  923.    * Results:
  924. !  *    TRUE.
  925.    *
  926.    * Side Effects:
  927. +  *    None.
  928.    *
  929.    *-----------------------------------------------------------------------
  930.    */
  931.   Bool
  932. ! LegalModifier(key)
  933.   {
  934.       return (TRUE);
  935.   }
  936.   
  937. ! static KeybdCtrl *pKbdCtrl = (KeybdCtrl *) 0;
  938.   
  939.   /*-
  940.    *-----------------------------------------------------------------------
  941. !  * sunBlockHandler --
  942. !  *    Tell the OS layer when to timeout to implement auto-repeat.
  943. !  *
  944.    * Results:
  945. +  *    None.
  946.    *
  947.    * Side Effects:
  948. +  *    The timeout value may be overwritten.
  949.    *
  950.    *-----------------------------------------------------------------------
  951.    */
  952.   void
  953. ! sunBlockHandler (index, pKeyboard, ppTime, pReadMask)
  954. !     int                index;        /* Screen index */
  955. !     DevicePtr        pKeyboard;    /* Keyboard for which to do auto-repeat */
  956. !     struct timeval  **ppTime;     /* Pointer to timeout to use */
  957. !     int                *pReadMask;    /* Mask the OS Layer will use for select. */
  958.   {
  959. !     if (repeatPhase == REPEAT_LONG) {
  960. !     /*
  961. !      * Beginning long timeout
  962. !      */
  963. !     repeatDelta = repeatLong;
  964. !     } else if (repeatPhase == REPEAT_SHORT) {
  965. !     /*
  966. !      * Beginning short timeout
  967. !      */
  968. !     repeatDelta = repeatShort;
  969. !     } else if (repeatPhase == REPEAT_NONE) {
  970. !     /*
  971. !      * No repeat necessary -- it can block as long as it wants to
  972. !      */
  973.       return;
  974. !     } else if (repeatPhase == REPEAT_TIMEOUT) {
  975. !     /*
  976. !      * Interrupted timeout -- use old timeout (that was modified by
  977. !      * select in the OS layer)
  978. !      */
  979. !     *ppTime = &repeatTimeout;
  980.       return;
  981. !     }
  982. !     repeatTimeout.tv_sec = repeatDelta / 1000;
  983. !     repeatTimeout.tv_usec = repeatDelta * 1000;
  984. !     repeatPhase = REPEAT_TIMEOUT;
  985. !     *ppTime = &repeatTimeout;
  986.   }
  987. ! /*-
  988. !  *-----------------------------------------------------------------------
  989. !  * sunWakeupHandler --
  990. !  *    Figure out if should do a repeat when the server wakes up. Because
  991. !  *    select will modify repeatTimeout to contain the time left, we
  992. !  *    can tell if the thing timed out.
  993. !  *
  994. !  * Results:
  995. !  *    None.
  996. !  *
  997. !  * Side Effects:
  998. !  *    repeatPhase may be changed to REPEAT_PENDING. If it is, *pNumReady
  999. !  *    will be set to 1 and the keyboard's stream marked ready in the
  1000. !  *    result mask.
  1001. !  *
  1002. !  *-----------------------------------------------------------------------
  1003. !  */
  1004.   void
  1005. ! sunWakeupHandler (index, pKeyboard, pNumReady, pReadMask)
  1006. !     int              index;        /* Screen index */
  1007. !     DevicePtr      pKeyboard;    /* Keyboard to repeat */
  1008. !     int              *pNumReady;     /* Pointer to number of ready streams */
  1009. !     int              *pReadMask;    /* Ready streams */
  1010. ! {
  1011. !     KbPrivPtr      pPriv;
  1012.   
  1013. !     pPriv = (KbPrivPtr)pKeyboard->devicePrivate;
  1014.       
  1015. !     if ((repeatPhase == REPEAT_TIMEOUT) && (pNumReady == 0)) {
  1016. !     repeatPhase = REPEAT_PENDING;
  1017.       ProcessInputEvents();
  1018. !     }
  1019.   }
  1020.